# from datetime import date, timedelta
#
# from django.shortcuts import render
# from rest_framework.generics import GenericAPIView, ListAPIView,CreateAPIView
# from rest_framework.response import Response
# #1.获取用户总数
# from rest_framework.views import APIView
#
# from goods.models import GoodCategoryVisit, SKU,GoodsCategory, SPU
# from meiduo_admin import serializers
# from meiduo_admin.serializers import SKUCategorySerializer,GoodSimpleSerializer
# from users.models import User
# from rest_framework.pagination import PageNumberPagination
# from .my_paginate import MyPageNumberPagination
# from rest_framework import mixins
# from rest_framework.viewsets import ModelViewSet
#
# #1,获取用户总数
# class UserTotalCountView(APIView):
#     def get(self,request):
#         #1.查询用户总数,filter(is_superuser=False,is_staff=False)这是排除掉管理员.
#         count=User.objects.filter(is_superuser=False,is_staff=False).count()
#
#         #2.返回响应
#         return Response({
#             "count":count
#         })
#
# #2,获取用户日增数
# class UserIncrementCountView(APIView):
#     def get(self,request):
#         #1.查询用户日赠数,date_joined__gte相当于创建的时间
#         today=date.today()
#         count=User.objects.filter(date_joined__gte=today).count()
#
#         #2.返回响应
#         return Response({
#             "count":count
#         })
# #3,获取日活数
# class UserDayActiveCountView(APIView):
#     def get(self,request):
#         #1.查询用户日活数,last_login__gte相当今天登陆过的用户
#         today=date.today()
#         count=User.objects.filter(last_login__gte=today).count()
#
#         #2.返回响应
#         return Response({
#             "count":count
#         })
# #4.获取日下单用户
# class UserDayOrderCountView(APIView):
#     def get(self,request):
#         #1.查询日下单用户,
#         today=date.today()
#         count=User.objects.filter(orderinfo__create_time__gte=today).count()
#
#         #2.返回响应
#         return Response({
#             "count":count
#         })
# #5.获取月新增用户
# class UserMonthIncreamentCountView(APIView):
#     def get(self,request):
#         #1.获取当天日期
#         today=date.today()
#         #2.获取30天前的日期
#         old_date=today-timedelta(days=29)
#         #3.循环查出每天的新增数,添加列表
#         user_list=[]
#         for i in range(0,30):
#
#         #3.1获取当天时间
#             current_date=old_date+timedelta(days=i)
#         #3.2获取当天时间的下一天
#             next_date=old_date+timedelta(days=i+1)
#         #3.3查询新增数
#             count=User.objects.filter(date_joined__gte=current_date,date_joined__lt=next_date).count()
#         #3.4添加数据
#             user_list.append({
#                 "date":current_date,
#                 "count":count
#             })
#
#         #4.返回响应
#         return Response(user_list)
# #6商品分类访问量.
# class UserGoodsVisitCountView(GenericAPIView):
#     serializer_class = serializers.UserGoodsDaySerializer
#
#     def get_queryset(self):
#         #1.获取当天日期
#         today=date.today()
#         #2.返回分类访问量
#         return GoodCategoryVisit.objects.filter(date__gte=today).all()
#
#     def get(self,request):
#         #1.查询分类访问量
#         good_visits=self.get_queryset()
#         #2.获取序列化器
#         serializer=self.get_serializer(instance=good_visits,many=True)
#         #3.返回响应
#         return Response(serializer.data)
#
# #7.获取用户信息
# class UserView(ListAPIView,CreateAPIView):
#     pagination_class = MyPageNumberPagination
#     # serializer_class = serializers.UserSerializer
#     # queryset = User.objects.all()
#     #重写获取数据化器的方法
#     def get_serializer_class(self):
#         if self.request.method == "GET":
#             return serializers.UserSerializer
#         else:
#             return serializers.UserAddSerializer
#     #重写数据源的方法
#     def get_queryset(self):
#         #1.获取过滤的关键字
#         keyword=self.request.query_params.get("keyword")
#         #2.判断是否过滤了
#         if keyword:
#             return User.objects.filter(username__contains=keyword)
#         else:
#             return User.objects.all()
#
#     # def post(self,request):
#         # # 1.获取数据
#         # dict_data = request.data
#         # #2.获取序列化器,校验,入库
#         # serializer=self.get_serializer(raise_exception=True)
#         # serializer.save()
#         #
#         # #3.返回响应
#         # return Response(serializer.data,status=201)
#         #使用mixin
#         # return self.create(request)
#
# #8.获取商品sku信息
# class SKUView(ModelViewSet):
#     pagination_class = MyPageNumberPagination
#     serializer_class = serializers.SKUSerializer
#     queryset = SKU.objects.all()
#     #1.重写get_queryset方法
#     def get_queryset(self):
#         #1.获取关键字
#         keyword= self.request.query_params.get("keyword")
#         #2.判断关键字
#         if keyword:
#             return SKU.objects.filter(name__contains=keyword).all()
#         else:
#             return SKU.objects.all()
#
# #9.获取商品sku分类(三级分类)
# class SKUCategoryView(ListAPIView):
#     serializer_class =SKUCategorySerializer
#     queryset = GoodsCategory.objects.filter(subs=None)
#
# #10.获取商品spu信息
# class GoodSimpleView(ListAPIView):
#     serializer_class = serializers.GoodSimpleSerializer
#     queryset = SPU.objects.all()
#
#
#
#
#
#
#
#
#
#
#
